package factory.new_object;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Client {

    public static void main(String[] args) {
        try {
            Class.forName("factory.new_object.ObjectTest");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        try {
            ObjectTest objectTest = ObjectTest.class.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        ObjectTest objectTest = new ObjectTest();
        ObjectTestInterface objectTestProxy = (ObjectTestInterface) Proxy.newProxyInstance(ObjectTestInterface.class.getClassLoader(), new Class[]{ObjectTestInterface.class},
                (Object proxy, Method method, Object[] handlerArgs) -> {
                    Object result;
                    result = method.invoke(objectTest, handlerArgs);
                    System.out.println("sdafasd");
                    return result;
                });
        objectTestProxy.doSomething();
    }
}
